package io.renren.modules.jxgk.service.impl;

import io.renren.common.utils.Query;
import io.renren.modules.jxgk.dao.FeedBackDao;
import io.renren.modules.jxgk.entity.DbFile;
import io.renren.modules.jxgk.entity.StudentFeedbackEntity;
import io.renren.modules.jxgk.entity.StudentFeedbackRequset;
import io.renren.modules.jxgk.service.FeedBackService;
import io.renren.modules.sys.entity.SysConfigEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.UUID;

/**
 * Created by Administrator on 2017/11/20 0020.
 */
@Service
@Transactional
public class FeedBackServiceImpl implements FeedBackService{

    @Autowired
    FeedBackDao feedBackDao;

    @Override
    public String saveFile( String path) {
        String uuid=UUID.randomUUID().toString();
        DbFile dbFile=new DbFile();
        dbFile.setId(uuid);
        dbFile.setPath(path);
        feedBackDao.save(dbFile);
        return uuid;
    }

    @Override
    public List<StudentFeedbackEntity> getfeedbackList(StudentFeedbackRequset studentFeedbackRequset) {

        List<StudentFeedbackEntity> studentFeedbackEntityList=feedBackDao.getfeedbackList(studentFeedbackRequset);
        for(int i=0;i<studentFeedbackEntityList.size();i++)
        {
            studentFeedbackEntityList.get(i).setImagePath(feedBackDao.getImagePathByStudentId(studentFeedbackEntityList.get(i).getId()));
        }

        return studentFeedbackEntityList;
    }

    public void saveStudentFeedbackEntity(StudentFeedbackEntity studentFeedbackEntity) {
        studentFeedbackEntity.setId(UUID.randomUUID().toString());
        String[] imageId=studentFeedbackEntity.getImageIds().split(",");
        for(int i=0;i<imageId.length;i++)
        {
            DbFile dbFile=new DbFile();
            dbFile.setId(imageId[i]);
            dbFile.setFeedbackInfoId(studentFeedbackEntity.getId());
            feedBackDao.updateDbFile(dbFile);
        }
        feedBackDao.saveStudentFeedbackEntity(studentFeedbackEntity);
    }

    @Override
    public List<StudentFeedbackEntity> getAllList(Query query) {
        return feedBackDao.getAllList(query);
    }

    @Override
    public int getTotal(Query query) {
        return feedBackDao.getTotal(query);
    }

    @Override
    public void deletefeedback(String id) {
        feedBackDao.deletefeedback(id);
    }
}
